package tableprocessor;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class FileProcessor
{
    //public enum Types{DOC,DOCX,XLS,XLSC,PDF,ODT,ODS};
    private List<FileInterface> fpList;
    //private
    public FileProcessor()
    {
        fpList = new ArrayList<FileInterface>();
        fpList.add(new MicrosoftOfficeFilesProcessor());
        fpList.add(new OpenOfficeFilesProcessor());
        fpList.add(new PDFFilesProcessor());
    }
    public Iterator<Table> load(String path)
    {
        for (Iterator<FileInterface> iter = fpList.iterator(); iter.hasNext();)
        {
            FileInterface fi = iter.next();
            if (fi.isIam(path))
            {
                return fi.parse(path);
            }
        }
        return null;
    }
    public boolean saveAs(String path,Table table) throws IOException
    {
        OutputStream out = new FileOutputStream(path);
        POIFSFileSystem pfs = new POIFSFileSystem();
        
// HWPFDocument document = null;
// WordExtractor we = new WordExtractor(document);

  //  pfs.createDocument(null, path);
//Range r;
//Table t;

   // pfs.createDocument(new ByteArrayInputStream(null), "1Table");
   // pfs.createDocument(new ByteArrayInputStream(null), "Data");
    // write the properties: 
   // writeProperties(pfs);       // <-- insert this 
    pfs.writeFilesystem(out);

        return false;
    }

}
